from typing import Optional, List, Literal
from pydantic import BaseModel, Field
import time


# 用户信息模型
class User(BaseModel):
    user_id: int = Field(..., description="用户ID")
    username: str = Field(..., description="用户名")
    nickname: str = Field("用户", description="昵称")
    avatar_url: Optional[str] = Field(None, description="头像URL")
    age: Optional[int] = Field(None, description="年龄", ge=0, le=150)
    gender: Optional[Literal["男", "女"]] = Field(None, description="性别")
    passworld: Optional[str] = Field(None, description="密码")
    created_at: int = Field(
        default_factory=lambda: int(time.time()), description="创建时间戳"
    )
    """创建时间戳，默认当前时间"""
    updated_at: int = Field(
        default_factory=lambda: int(time.time()), description="更新时间戳"
    )
    """更新时间戳，默认当前时间"""


# 用户响应模型（不包含敏感信息）
class UserDateResponse(BaseModel):
    message: str = Field("操作成功", description="响应消息")
    user_data: User = Field(..., description="用户数据")

    class Config:
        # 排除敏感字段
        exclude = {"password"}


# 用户注册模型
class UserRegister(BaseModel):
    username: str = Field(..., description="用户名", min_length=3, max_length=50)
    password: str = Field(..., description="密码", min_length=6, max_length=20)
    created_at: int = Field(
        default_factory=lambda: int(time.time()), description="创建时间戳"
    )
    """创建时间戳，默认当前时间"""
    updated_at: int = Field(
        default_factory=lambda: int(time.time()), description="更新时间戳"
    )
    """更新时间戳，默认当前时间"""


# 用户登录模型
class UserLogin(BaseModel):
    username: str = Field(..., description="用户名")
    password: str = Field(..., description="密码")


# 用户更新模型
class UserUpdate(BaseModel):
    nickname: Optional[str] = Field(None, description="昵称", max_length=50)
    avatar_url: Optional[str] = Field(None, description="头像URL")
    age: Optional[int] = Field(None, description="年龄", ge=0, le=150)
    gender: Optional[str] = Field(None, description="性别")
    password: Optional[str] = Field(
        None, description="新密码", min_length=6, max_length=20
    )
    updated_at: int = Field(
        default_factory=lambda: int(time.time()), description="更新时间戳"
    )
    """更新时间戳，默认当前时间"""


# 登录成功响应模型
class UserLoginResponse(BaseModel):
    message: str = Field("登录成功", description="响应消息")
    token: str = Field(..., description="JWT令牌")
